//***********************************************************************************

// Author: Aravindh U095232L

//***********************************************************************************

//To find the grid where the player is in currently
function findgrid(object)
{
	this.width = canvas.width;
	this.height = canvas.height;
	var arr = { x:object.pos_x/20, y:object.pos_y/20};	
	return arr;
}

//To draw the main grid lines
function drawgrid()
{
	ctx.save();

	ctx.beginPath();
	ctx.globalAlpha=0.1;
	for(var i = 0; i <580;i+=20)
	{
		ctx.moveTo(0, i);
		ctx.lineTo(1200, i );
	}
	for(var i = 0; i <1200;i+=20)
	{
		ctx.moveTo(i, 0);
		ctx.lineTo(i, 580 );
	}
	ctx.stroke();

	ctx.restore();
}

//To find the current abstraction level of npc        
function findlevel(player, object)
{
	var pos = findgrid(object);

	if( pos.x>=(player.grid.x-6) && pos.x<=(player.grid.x+6) )
		if( pos.y>=(player.grid.y-6) && pos.y<=(player.grid.y+6) )
		{
			object.prev_level = object.level;
			object.level = 1;
			return;
		}

	if( pos.x>=(player.grid.x-12) && pos.x<=(player.grid.x+12) )
		if( pos.y>=(player.grid.y-12) && pos.y<=(player.grid.y+12) )
		{
			object.prev_level = object.level;
			object.level = 2;	
			return;
		}

	object.prev_level = object.level;
	object.level = 3;

}

//To draw the level abstraction boxes
function drawlevel(object)
{	
	ctx.save();
	ctx.globalAlpha=0.1;
	ctx.fillStyle = "rgb(100,200,200)";
	ctx.fillRect(object.pos_x-120, object.pos_y-120,260,260);
	ctx.fillStyle = "rgb(200,50,10)";
	ctx.fillRect(object.pos_x-240, object.pos_y-240,500,500);
	ctx.restore();
}